const express = require('express');
const router = express.Router();
const { 
  createComment, 
  getComments, 
  updateComment, 
  deleteComment,
  toggleLike
} = require('../controllers/commentController');
const { protect } = require('../middleware/auth');
/**
 * @swagger
 * tags:
 *   name: Comments
 *   description: 评论相关接口
 */

/**
 * @swagger
 * /api/comments:
 *   post:
 *     tags: [Comments]
 *     summary: 创建评论
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - postId
 *               - content
 *             properties:
 *               postId:
 *                 type: string
 *                 description: 文章ID
 *               content:
 *                 type: string
 *                 description: 评论内容
 *     responses:
 *       201:
 *         description: 评论创建成功
 *       401:
 *         description: 未授权
 *       404:
 *         description: 文章不存在
 *   get:
 *     tags: [Comments]
 *     summary: 获取文章评论列表
 *     parameters:
 *       - in: query
 *         name: postId
 *         required: true
 *         schema:
 *           type: string
 *         description: 文章ID
 *       - in: query
 *         name: page
 *         schema:
 *           type: integer
 *           default: 1
 *         description: 页码
 *       - in: query
 *         name: limit
 *         schema:
 *           type: integer
 *           default: 10
 *         description: 每页数量
 *     responses:
 *       200:
 *         description: 成功获取评论列表
 */
// 创建评论（需要登录）
router.post('/', protect, createComment);

// 获取文章的所有评论
/**
 * @swagger
 * /api/comments/user:
 *   get:
 *     tags: [Comments]
 *     summary: 获取当前用户的评论列表
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: page
 *         schema:
 *           type: integer
 *           default: 1
 *         description: 页码
 *       - in: query
 *         name: limit
 *         schema:
 *           type: integer
 *           default: 10
 *         description: 每页数量
 *     responses:
 *       200:
 *         description: 成功获取用户评论列表
 *       401:
 *         description: 未授权
 */
router.get('/post/:postId', getComments);

// 更新评论（需要登录）
/**
 * @swagger
 * /api/comments/{id}:
 *   put:
 *     tags: [Comments]
 *     summary: 更新评论
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: string
 *         description: 评论ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - content
 *             properties:
 *               content:
 *                 type: string
 *                 description: 评论内容
 *     responses:
 *       200:
 *         description: 评论更新成功
 *       401:
 *         description: 未授权
 *       403:
 *         description: 无权限修改
 *       404:
 *         description: 评论不存在
 */
router.put('/:id', protect, updateComment);

// 删除评论（需要登录）
/**
 * @swagger
 * /api/comments/{id}:
 *   delete:
 *     tags: [Comments]
 *     summary: 删除评论
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: string
 *         description: 评论ID
 *     responses:
 *       200:
 *         description: 评论删除成功
 *       401:
 *         description: 未授权
 *       403:
 *         description: 无权限删除
 *       404:
 *         description: 评论不存在
 */
router.delete('/:id', protect, deleteComment);

module.exports = router;